﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TestApp
{
	/// <summary>
	/// Interaction logic for Window1.xaml
	/// </summary>
	public partial class Window1 : Window
	{
		public Window1()
		{
			InitializeComponent();
			SyntaxTextBox.SyntaxLexer = new TokenParser ();
		}

		private void MenuItem_Click_1(object sender, RoutedEventArgs e)
		{
			Close();
		}

		private void LightThemeMenuItem_Click(object sender, RoutedEventArgs e)
		{
			SyntaxTextBox.Style = FindResource("LightTheme") as Style;
			LightThemeMenuItem.IsChecked = true;
			DarkThemeMenuItem.IsChecked = false;
			ExperimentalThemeMenuItem.IsChecked = false;
		}

		private void DarkThemeMenuItem_Click(object sender, RoutedEventArgs e)
		{
			SyntaxTextBox.Style = FindResource("DarkTheme") as Style;
			LightThemeMenuItem.IsChecked = false;
			DarkThemeMenuItem.IsChecked = true;
			ExperimentalThemeMenuItem.IsChecked = false;
		}

		private void ExperimentalThemeMenuItem_Click(object sender, RoutedEventArgs e)
		{
			SyntaxTextBox.Style = FindResource("ExperimentalTheme") as Style;
			LightThemeMenuItem.IsChecked = false;
			DarkThemeMenuItem.IsChecked = false;
			ExperimentalThemeMenuItem.IsChecked = true;
		}

		private void SearchTextBox_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.Key == Key.Return)
			{
				string[] words = SearchTextBox.Text.Split(',', ' ', ';', '-');
				SyntaxTextBox.HighlightText.Clear();

				foreach (string word in words)
					SyntaxTextBox.HighlightText.Add(word);
			}
		}

		private void SyntaxTextBox_TextChanged ( object sender, TextChangedEventArgs e )
		{
			( this.DataContext as QueryManager ).Query = SyntaxTextBox.Text;
		}
	}
}
